import MES from '@/utils/mesUtils';

const state = {
  count: 0,
  newestDevSn: 0, // 最新设备编号
  /**
   * 分组数据store
   */
  luoTongGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  luoTongGroupState1: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  xiShaGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  txcsomlGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  shuMianJiGroupState: {
    code: 0,
    data1: [],
    data2: [],
    msg: '',
    status: ''
  },
  bingTiaoGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  duoCangGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  zhuaMianGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  kaiMianGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  qinghuaGroupState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  /**
   * 实时数据store
   */
  bingTiaoNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  // 梳棉机、梳棉机A共同处理
  shuMianJiNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  txcsomlNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  xiShaNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  luoTongNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  duoCangNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  kaiMianNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  zhuaMianNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  },
  dongLiNewestState: {
    code: 0,
    data: [],
    msg: '',
    status: ''
  }
};
const mutations = {
  /**
   * 分组数据
   */
  // 更新并条分组数据
  optBingTiaoGroup: (state, params) => {
    const { bingTiaoGroupState } = state;
    state.bingTiaoGroupState = { ...bingTiaoGroupState, ...params };
  },
  // 更新梳棉机分组数据
  optShuMianJiGroup: (state, params) => {
    const { shuMianJiGroupState } = state;
    state.shuMianJiGroupState = { ...shuMianJiGroupState, ...params };
  },
  // 更新太行细纱欧姆龙数据
  optTxcsomlGroup: (state, params) => {
    const { txcsomlGroupState } = state;
    state.txcsomlGroupState = { ...txcsomlGroupState, ...params };
  },
  // 获取细纱分组数据
  optXiShaGroup: (state, params) => {
    const { xiShaGroupState } = state;
    state.xiShaGroupState = { ...xiShaGroupState, ...params };
    state.xiShaGroupState.data.push(params.data);
  },
  // 获取络筒分组数据1
  optLuoTongGroup1: (state, params) => {
    const { luoTongGroupState1 } = state;
    state.luoTongGroupState1 = { ...luoTongGroupState1, ...params };
    state.luoTongGroupState1.data.push(params.data);
  },
  // 获取络筒分组数据
  optLuoTongGroup: (state, params) => {
    const { luoTongGroupState } = state;
    state.luoTongGroupState = { ...luoTongGroupState, ...params };
    state.luoTongGroupState.data.push(params.data);
  },
  // 获取多仓分组数据
  optDuoCangGroup: (state, params) => {
    const { duoCangGroupState } = state;
    state.duoCangGroupState = { ...duoCangGroupState, ...params };
    state.duoCangGroupState.data.push(params.data);
  },
  // 获取开棉机分组数据
  optKaiMianGroup: (state, params) => {
    const { kaiMianGroupState } = state;
    state.kaiMianGroupState = { ...kaiMianGroupState, ...params };
    state.kaiMianGroupState.data.push(params.data);
  },
  // 获取抓棉分组数据
  optZhuaMianGroup: (state, params) => {
    const { zhuaMianGroupState } = state;
    state.zhuaMianGroupState = { ...zhuaMianGroupState, ...params };
    state.zhuaMianGroupState.data.push(params.data);
  },
  // 获取清化分组数据
  optQingHuaGroup: (state, params) => {
    const { qingHuaGroupState } = state;
    state.qingHuaGroupState = { ...qingHuaGroupState, ...params };
    state.qingHuaGroupState.data.push(params.data);
  },
  /**
   * 实时数据
   */
  // 清空实时数据
  removeAllNewest: state => {
    state.bingTiaoNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.shuMianJiNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.txcsomlNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.xiShaNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.luoTongNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.duoCangNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.zhuaMianNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.kaiMianNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
    state.dongLiNewestState = {
      code: 0,
      data: [],
      msg: '',
      status: ''
    };
  },
  // 更新并条实时数据
  optBingTiaoNewest: (state, params) => {
    const { bingTiaoNewestState } = state;
    state.bingTiaoNewestState = { ...bingTiaoNewestState, ...params };
  },
  // 更新梳棉机实时数据
  optShuMianJiNewest: (state, params) => {
    const { shuMianJiNewestState } = state;
    state.shuMianJiNewestState = { ...shuMianJiNewestState, ...params };
  },
  // 更新太行细纱欧姆龙实时数据
  optTxcsomlNewest: (state, params) => {
    const { txcsomlNewestState } = state;
    state.txcsomlNewestState = { ...txcsomlNewestState, ...params };
  },
  // 更新细纱实时数据
  optXiShaNewest: (state, params) => {
    const { xiShaNewestState } = state;
    state.xiShaNewestState = { ...xiShaNewestState, ...params };
  },
  // 更新络筒实时数据
  optLuoTongNewest: (state, params) => {
    const { luoTongNewestState } = state;
    state.luoTongNewestState = { ...luoTongNewestState, ...params };
  },
  // 更新多仓实时数据
  optDuoCangNewest: (state, params) => {
    const { duoCangNewestState } = state;
    state.duoCangNewestState = { ...duoCangNewestState, ...params };
  },
  // 更新开棉实时数据
  optKaiMianNewest: (state, params) => {
    const { kaiMianNewestState } = state;
    state.kaiMianNewestState = { ...kaiMianNewestState, ...params };
  },
  // 更新抓棉实时数据
  optZhuaMianNewest: (state, params) => {
    const { zhuaMianNewestState } = state;
    state.zhuaMianNewestState = { ...zhuaMianNewestState, ...params };
  },
  // 更新动力实时数据
  optDongLiNewest: (state, params) => {
    const { dongLiNewestState } = state;
    state.dongLiNewestState = { ...dongLiNewestState, ...params };
  }
};
const actions = {
  /**
   * 分组数据
   */
  // 获取并条分组数据
  actBingTiaoGroup: ({ commit }, params) => {
    MES.queryGroupBingTiaoList().then(res => {
      // 请求成功更新数据
      commit('optBingTiaoGroup', res);
    });
  },
  // 获取梳棉机分组数据
  actShuMianJiGroup: ({ commit }, params) => {
    MES.queryGroupShuMianJiList().then(res => {
      commit('optShuMianJiGroup', res);
    });
  },
  // 获取太行粗纱欧姆龙分组数据
  actTxcsomlGroup: ({ commit }, params) => {
    MES.queryGroupTxcsomlList().then(res => {
      commit('optTxcsomlGroup', res);
    });
  },
  // 获取细纱分组数据
  actXiShaGroup: ({ commit }, params) => {
    MES.queryGroupXiShaList().then(res => {
      commit('optXiShaGroup', res);
    });
  },
  // 获取络筒分组数据
  actLuoTongGroup: ({ commit }, params) => {
    MES.queryGroupLuoTongList().then(res => {
      commit('optLuoTongGroup', res);
    });
  },
  // 获取络筒分组数据1
  actLuoTongGroup1: ({ commit }, params) => {
    MES.queryGroupLuoTongList1(params).then(res => {
      commit('optLuoTongGroup1', res);
    });
  },
  // 获取多仓分组数据
  actDuoCangGroup: ({ commit }, params) => {
    MES.queryGroupDuoCangList().then(res => {
      commit('optDuoCangGroup', res);
    });
  },
  // 获取开棉分组数据
  actKaiMianGroup: ({ commit }, params) => {
    MES.queryGroupKaiMianList().then(res => {
      commit('optKaiMianGroup', res);
    });
  },
  // 获取抓棉分组数据
  actZhuaMianGroup: ({ commit }, params) => {
    MES.queryGroupZhuaMianList().then(res => {
      commit('optZhuaMianGroup', res);
    });
  },
  // 获取清化分组数据
  actQingHuaGroup: ({ commit }, params) => {
    MES.queryGroupQingHuaList().then(res => {
      commit('optQingHuaGroup', res);
    });
  },
  /**
   * 实时数据
   */
  // 获取并条实时数据
  actBingTiaoNewest: ({ commit }, params) => {
    MES.queryNewestBingTiao(params).then(res => {
      // 请求成功更新数据
      commit('optBingTiaoNewest', res);
    });
  },
  // 获取梳棉机实时数据
  actShuMianJiNewest: ({ commit }, params) => {
    MES.queryNewestShuMianji(params).then(res => {
      commit('optShuMianJiNewest', res);
    });
  },
  // 获取梳棉机A实时数据
  actShuMianJiANewest: ({ commit }, params) => {
    MES.queryNewestShuMianjiA(params).then(res => {
      commit('optShuMianJiNewest', res);
    });
  },
  // 获取太行粗纱欧姆龙实时数据
  actTxcsomlNewest: ({ commit }, params) => {
    MES.queryNewestTxcsoml(params).then(res => {
      commit('optTxcsomlNewest', res);
    });
  },
  // 获取新粗纱欧姆龙实时数据
  actCuShaJiNewest: ({ commit }, params) => {
    MES.queryNewestCuShaji(params).then(res => {
      commit('optTxcsomlNewest', res);
    });
  },
  // 获取细纱实时数据
  actXiShaNewest: ({ commit }, params) => {
    MES.queryNewestXiShaMzl(params).then(res => {
      commit('optXiShaNewest', res);
    });
  },
  // 获取络筒实时数据
  actLuoTongNewest: ({ commit }, params) => {
    MES.queryNewestLuoTong(params).then(res => {
      commit('optLuoTongNewest', res);
    });
  },
  // 获取多仓实时数据
  actDuoCangNewest: ({ commit }, params) => {
    MES.queryNewestDuoCang(params).then(res => {
      commit('optDuoCangNewest', res);
    });
  },
  // 获取开棉实时数据
  actKaiMianNewest: ({ commit }, params) => {
    MES.queryNewestKaiMian(params).then(res => {
      commit('optKaiMianNewest', res);
    });
  },
  // 获取抓棉实时数据
  actZhuaMianNewest: ({ commit }, params) => {
    MES.queryNewestZhuaMian(params).then(res => {
      commit('optZhuaMianNewest', res);
    });
  },
  // 获取动力实时数据
  actDongLiNewest: ({ commit }, params) => {
    MES.queryNewestDongLi(params).then(res => {
      commit('optDongLiNewest', res);
    });
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
